import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { HttpServicesProvider } from '../../providers/http-services/http-services';
import { ConfigProvider } from '../../providers/config/config';

/**
 * Generated class for the ProductListPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-product-list',
  templateUrl: 'product-list.html',
})
export class ProductListPage {
  public list = []
  private cid = ''
  private page = 1
  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public httpServices: HttpServicesProvider,
    public config: ConfigProvider
  ) {
    this.cid = this.navParams.get('cid')
    this.getProductList('')
  }

  // 获取表单
  getProductList(InfiniteScroll) {
    this.httpServices.requestData('api/plist?cid=' + this.cid + '&page=' + this.page, data => {
      this.list = this.list.concat(data.result)
      if (InfiniteScroll) {
        // 请求加载完成
        InfiniteScroll.complete()
        if (data.result.length < 10) {
          // 当没有数据的时候执行的代码
          InfiniteScroll.enable(false)
        }
      }
      this.page++
    })
  }

  // 加载更多
  doLoadMore(InfiniteScroll) {
    this.getProductList(InfiniteScroll)
  }
}

